<template>
  <div class="condition-wrapper">
    <Input ref="searchInput" placeholder="请输入订单号" class="input-cls" @search="handleSearch" />
    <el-date-picker
      v-model="value"
      type="daterange"
      align="right"
      unlink-panels
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      :picker-options="pickerOptions"
      format="yyyy 年 MM 月 dd 日"
      value-format="yyyy-MM-dd HH:mm:ss"
      :default-time="['00:00:00', '23:59:59']"
      @change="handleChange"
    />
  </div>
</template>
<script>
import Input from '@/common/input'
export default {
  components: {
    Input
  },
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      value: []
    }
  },
  methods: {
    handleSearch(query) {
      this.$emit('search', query)
    },
    handleChange(time) {
      this.$emit('datePicker', time)
    },
    clear() {
      this.value = []
    }
  }
}
</script>
<style lang="scss" scoped>
.condition-wrapper {
  display: flex;
  align-items: center;
  .totle {
    line-height: 26px;
    color: rgba(245, 108, 108, 1);
    font-size: 18px;
    text-align: left;
    font-family: Roboto;
    margin-right: 9px;
    font-weight: bold;
  }
  .input-cls {
    margin-right: 21px;
  }
}
</style>
